% isetup.m
% inflation index for ada or other scores



clear
clear functions 
clc

%%%%%%%%%%%%%%%%%%%%%%%% set constants  %%%%%%%%%%%%%%%%%%%%%%%%%%%%

IterSteps = 1000;
OptStep = 1;
%Newtsteps = 1;
%lamsteps = 20;

%%%%%%%%%%%%%%%%%%%%%%%%% load data  %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% the following subroutine 1) reads in data, 2) adjusts polarity
% 3) reads in (or sets) seed a and b vectors 4) sets other parameters
% such as MaxMem, BeginYear, etc.
% Score data must be in the following form:
% Column 1: vector of years, BeginYear to HEndYear. eg 940 to 988.  not nec. 1 to 49
% Column 2: chamber => vector of 1's for House and 2's for Senate
% Column 3: ICPSR # (or some other unique identifier)
% Column 4: ACU Score

%The following matlab file loads the data for ACU scores for 1971-1999.  Be sure that
%you check this file to ensure that the file where you store the data has the same name
%as the files called by ildc7199
ildc7199;


%%%%%%%%%%%%%%%%%%%%%% adjust years %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% The following adjusts senate years.  Senate data is treated as new
% years that follow House End Year.

for s=1:Ns
  %%%% adjust Senate data
  if chamber(s) == 2,
    t(s) = HEndYear + 1 + (t(s)-BeginYear);
  end  % if chamber = Senate
end  
    
disp('years adjusted');

%%%%%%%%%%%%%%%%%%%%%%%%%% create i-vector %%%%%%%%%%%%%%%%%%%%%%%%%%%
i  = zeros(Ns,1);

igeti;

disp('i vector created')

%%%%% set Nx=kx, and k;  and initialize bb, bbsig, invW  %%%%%%%%%%

Nx = length(ic);
kx = Nx;
ksig = 1;
k  = ka + kb + kx + ksig;
bb = zeros(k,1);
bbold = zeros(k,1);
bbsig = zeros(k,1);

%%%%%%%%%%%%%%%%%%% set bbon  %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

bbon = ones(k,1);
bbon(baseq) = 0;    % base for a 
bbon(ka+baseq) = 0; % base for b
%for q = 2:ka, bbon(q) = 0;
%for q = (ka+1):(ka+kb), bbon(q) = 0; end;
%bbon(k) = 0;

kend = k; % set kend to the last q for which bbon(q) is 1


%%%%%%%%%%%%%%%%%%%% set Ti and It  %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

% Ti(i) = |T(i)| = number years i served
% It(t) = |I(t)| = number of members serving in year t

igetti;

disp('Ti and It created')

%%%%%%%%%%%%%%%%% get aNs and bNs %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

igetans;
igetbns;

%%%%%%%% figure seed values for x(r) %%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%load x.dat;
x= zeros(kx,1);
igetx;
disp('igetx done')


%%%%%%%%% figure seed value for sig %%%%%%%%%%%%%%%%%%%%%%%%%%%%%

igetsig;
sig = sqrt(sig2);
disp('igetsig done')


%%%%%%%%%%%%%%% convert a, b, x, sig to bb %%%%%%%%%%%%%%%%%%%

igetbb;

%%%%%%%%%%%%%%%%% save a, b, and x  %%%%%%%%%%%%%%%%%%%%%%%%%%

save a a;
save b b;
save x x;
save all;


%%%%%%%%%%%%%%%%%%%% run iiter %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% iiter;


